import React, { Component } from 'react';
import { connect } from 'dva';
import { LoadingOutlined } from '@ant-design/icons';
import { Spin } from 'antd';
import router from 'umi/router';

const antIcon = <LoadingOutlined style={{ fontSize: 32 }} spin />;

const divStyle: any = {
  width: '100%',
  height: '100%',
  textAlign: 'center',
  paddingTop: 100,
  alignItems: 'center',
  fontSize: 16,
};

interface WelcomeProps {
  menuInfo: any;
}

@connect(({
  menu: { menuInfo },
}: any) => ({ menuInfo }))

class Welcome extends Component<WelcomeProps> {
  componentDidMount() {
    const { menuInfo } = this.props;
    if (menuInfo.length > 0) {
      menuInfo.forEach((menu: any) => {
        if (menu.children && menu.children.length) {
          router.replace(menu.children[0].path);
        }
      });
    }
  }

  render() {
    return (
      <div style={divStyle}>
        <Spin indicator={antIcon} />
        <p style={{ marginTop: 12 }}>加载中...</p>
      </div>
    );
  }
}

export default Welcome;
